$(document).ready(function() 
			{ 
				$("#error").hide();
				var btn = $("#divSubmit");
				var name = $("#LoginForm_username");
				var pass = $("#LoginForm_password");
				var error = $("#error");
				name.focus();
				
				var onkeydown = function(e)
				{
					
					if (e.keyCode == 13)
					{
						submit(null, e);
					}
				}

				var submit = function(b, e)
				{

					if (name.val() == "") 
					{
						name.focus(); return;
					}
					if (pass.val() == "")
					{
						pass.focus(); return;
					}
                    $('#loginForm').form('submit',{
                        success: showResponse
                    })

				};

				name.on("keydown", onkeydown );

				pass.on("keydown", onkeydown);


				$("#divSubmit").on("click", function(){
					submit();
				});

				name.on("click", function(){hideError();});
				pass.on("click", function(){hideError();});

				var hideError = function()
				{
					if (error.css("display") != "none")
					{
						$("#error").hide("drop", {}, 100);
					}
				}

				var showResponse = function(v){
					v = eval("data=" + v);
					if (v.success){
						window.location = v.data.returnUrl;
					}
					else {
						$("#error").show( "drop", {},  200, callback );
					}
				}

				//callback function to bring a hidden box back
				function callback(b) 
				{
					/*
					setTimeout(function() {
						$("#error").hide("drop");
					}, 3000 );
					 */
				};
			});